define(["jquery"],function(){
	var comm = {};

	/**
	 * 根据type判断加载题型
	 */
	comm.judgeLoadTpl = function(arr){
		for (var i=0; i < arr.length; i++) {
			if( arr[i].type == "qusetion_group" ) arr[i].type = "question_group"; //兼容之前手误写错的 
			if( i == 0){
				var h = '{{if value.type=="'+ arr[i] +'"}}';
			}else{
				h += '{{else if value.type=="'+ arr[i] +'"}}';
			}
			h += '{{include "tpl_'+ arr[i] +'",value}}';
			if( i == arr.length - 1 ) h += '{{/if}}';
		}
		return h;
	}

	/**
	 * 单选框可点击取消选中
	 */
	comm.cancelRadioChecked = function(){
		$("input:radio").parent().mousedown(function(event){
			event = event || window.event;
		    var target = event.target || event.srcElement;
		    if($(target).is('input')){ // 点击的是 input
		    	target.previousValue = target.checked;
		    }else{	// 点击的是 input的父级label
		    	target.control.previousValue = target.control.checked;
		    }
		});
		$("input:radio").parent().click(function(event){
			event = event || window.event;
		    var target = event.target || event.srcElement;
		    if($(target).is('input')){
	        	if (target.previousValue) {
		            target.checked = false;
	        	}
			}else{
				return;
			}
		});
	}

	return comm;
});